<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
use Mail;
class ForgetController extends Controller
{
    //找回密码
    public function forget()
    {
        return view('admin.forget.forgetEmail');
    }
    //sendEmail
    public function sendEmail(Request $request)
    {
        //dd($request -> all());
         $data = $request -> except('_token');
         $res = DB::table('user') -> where('email',$data['email']) -> first();
         //dd($res);
         if(!$res)
        {
            return back() -> with(['info' => '您输输入的邮箱不存在']);
        }
        // Mail::raw('哈哈哈哈', function ($message) {
        //     $message -> subject('jjj');
        //     $message -> to('qjandqjl@163.com');

        Mail::send('emails.html', [], function ($m) use ($data) {
           $m -> subject('这是邮件');
           $m -> to($data['email']);
        });
    }
    public function config()
    {

        return view('admin.config.config');
    }
    public function doconfig(Request $request)
    {
        $data = $request -> except('_token');
        $data['status'] = 0;
         if($request -> hasFile('pic'))
         {
            if($request -> file('pic') -> isValid())
            {
                $suffix = $request -> file('pic') -> getClientOriginalExtension();
                $fileName = time().mt_rand(10000,99999).'.'.$suffix;

                $move = $request -> file('pic') -> move('./uploads/yhtx',$fileName);

                if($move)
                {
                    $data['pic'] = $fileName;
                }
                else
                {
                    $data['pic'] = 'default.jpg';
                }
            }
            else
                {
                    $data['pic'] = 'default.jpg';
                }
         }
         else
                {
                    $data['pic'] = 'default.jpg';
                }
       //dd($data);
       $array = array(
            'webname' => $data['webname'],
            'copyright' => $data['copyright'],
            'logo' => $data['pic'],

            'status' => 0
        );
        $res = DB::table('webcofig') -> where('id','1') -> update($array);
        if($res)
        {
            return redirect('admin/config/config');
        }
    }

}